#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTcpSocket>
#include <QPushButton>
#include <QLabel>
#include <QColor>
#include <QLineEdit>
#include <QPainter>
#include <QPixmap>
#include <QBitmap>
#include <QDebug>

#define MWINHEIGHT 1030
#define MWINWIDTH 680

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();


    bool isLed = false;
    bool isFan = false;
    bool isBuz = false;
    bool isDoor = false;
    QLabel *labelControl = new QLabel(this);            //控制区标签
    QPushButton *btnLed = new QPushButton(this);        //LED灯开关
    QPushButton *btnFan = new QPushButton(this);        //风扇开关
    QPushButton *btnBuzzer = new QPushButton(this);     //蜂鸣器开关
    QPushButton *btnDoor = new QPushButton(this);       //门开关

    bool isEnvironmentSocket = false;
    QTcpSocket *EnvironmentSocket = new QTcpSocket(this);//套接字
    QPushButton *btnEnvironment = new QPushButton(this);   //环境监测按钮
    QLabel *labelEnvironment = new QLabel(this);        //环境区标签
    QLabel *labelTemp = new QLabel(this);               //温度
    QLabel *labelHum = new QLabel(this);                //湿度
    QLabel *labelLight = new QLabel(this);              //光强
    int temp = 20;
    int hum = 20;
    int light = 20;


    bool isTcpSocket = false;
    QTcpSocket *tcpSocket = new QTcpSocket(this);       //套接字
    QPushButton *btnNetwork = new QPushButton(this);    //网络连接开关
    QLabel *labelIP = new QLabel(this);                 //ip标签
    QLabel *labelPort = new QLabel(this);               //port标签
    QLineEdit *lineIP = new QLineEdit(this);            //ip文本框
    QLineEdit *linePort = new QLineEdit(this);          //port文本框
    bool isIntImg = true;
    int size = 0;
    char img[1024*1024] = {0};
    char buf_len[32] = {0};


    QLabel *labelPicture = new QLabel(this);            //图片框

    bool isVideo = false;
    bool isVoice = false;
    bool isTcpV = false;
    QTcpSocket *tcpV = new QTcpSocket(this);
    QPushButton *btnVideoideo = new QPushButton(this);  //视频开关
    QLabel *labelVoice = new QLabel(this);              //语音标签
    QPushButton *btnVoice = new QPushButton(this);      //语音开关


    void ini();                  //初始化
    void iniCenter();           //初始化按钮功能
    void iniTcp();              //初始化网络

    void paintEvent(QPaintEvent *);

    QString strCat(QString str, int n);
    void setBtnBack(QPushButton *btn, QString icon, int w, int h);

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H








